package cn.wolfcode.wms.domain;

import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Product extends BaseDomain {
    private String name;

    private String sn;

    private BigDecimal costPrice;

    private BigDecimal salePrice;

    private String imagePath;

    private String intro;

    private Long brandId;

    private String brandName;

    public String getMinImagePath() {
        String prefix = this.imagePath.substring(0, this.imagePath.indexOf("."));
        String suffix = this.imagePath.substring(this.imagePath.indexOf("."));
        return prefix + "_small" + suffix;
    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", this.getId());
        map.put("name", name);
        map.put("brandName", brandName);
        map.put("costPrice", costPrice);
        map.put("salePrice", salePrice);
        String jsonString = JSONUtils.toJSONString(map);
        return jsonString;
    }
}